<?php

namespace app\admin\controller;

use app\service\model\AddonModel;
use app\service\Y;
use think\facade\Cache;
/**
 * 首页 控制器
 */
class System extends BaseAdmin
{
    /**
     * 缓存设置
     * @return \think\response\Json
     */
	public function cache(): \think\response\Json
    {
        $tag = input("tag", '');
        Cache::tag($tag)->clear();
        return Y::success([], '清理成功');
	}

    /**
     * 插件管理
     * @return array|mixed|\think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
	public function addon()
	{
		if (request()->isPost()) {
			$addon_name = input("addon_name");
			$tag = input("tag", "install");
			if ($tag == 'install') {
				$res = AddonModel::install($addon_name);
			} else {
				$res = AddonModel::uninstall($addon_name);
			}
            return $res;
		}
		$uninstall = AddonModel::getUninstallAddonList();
		$install = AddonModel::getAddonList();
		return Y::success(compact('uninstall', 'install'));
	}
}
